<?php

/**
 * FootballFactory, Copyright Robin Loop & Pascal Wirz, 2014
 * ---
 * Template zum Editieren eines Spiels
 *
 * @author Robin
 */

require('templates/header.php');
?>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <!-- JQuery -->
        <script src="../js/jquery-1.8.3.min.js"></script>
        <script src="../js/jquery-ui-1.9.2.custom.min.js"></script>
        
        <!-- JS -->
        <script src="../js/admin_menu.js"></script>
        
        <!-- CSS -->
        <link href="../css/admin.css" rel="stylesheet">
        <link href="../css/smoothness/jquery-ui-1.9.2.custom.css" rel="stylesheet">
        
    </head>

    <body>
        
        <?php include 'menu.php'; ?>
        
        <div>
            <h1>Spiel editieren: <?php echo $game->getHometeam()." - ".$game->getAwayteam(); ?></h1>
                
            <div>
                <form id="editgameform" action="game.php?action=save" method="post">
                    <input type="hidden" name="game_id" value="<?php echo $game->getId() ?>"/>
                    <ul>
                        <li>
                            <label for="game_hometeam">Heimteam</label>
                            <input type="text" name="game_hometeam" placeholder="Heimteam" required autofocus maxlength="255" value="<?php echo htmlspecialchars($game->getHometeam()) ?>" />
                        </li>
                        <li>
                            <label for="game_awayteam">Auswaertsteam</label>
                            <input type="text" name="game_awayteam" placeholder="Auswärtsteam" required maxlength="255" value="<?php echo htmlspecialchars($game->getAwayteam()) ?>" />
                        </li>
						<li>
                            <label for="game_date">Datum</label>
                            <input type="datetime-local" name="game_date" placeholder="dd.mm.yyyy hh:mm:ss" required maxlength="20" value="<?php echo $game->getDate() ? date('Y-m-d', strtotime($game->getDate()))."T".date('H:i:s', strtotime($game->getDate())) : "" ?>" />
                        </li>
						<li>
							<label for="game_type">Art</label>
							<select id="game_type" name="game_type">
							<?php foreach ($gametypes as $gametype) { ?>
                                                        <option value="<?php echo $gametype->getId(); ?>" <?php if ($gametype->getId() == $game->getType()) { echo "selected"; } else { echo ""; } ?>><?php if ($gametype->getHome() == 1) { $ortString = "heim"; } else {$ortString = "auswärts";} echo $gametype->getName()." - ".$ortString; ?></option>
							<?php } ?>
							</select>
						</li>
                        <li>
                            <label for="game_imagelink">Bild-Link</label>
                            <input type="text" name="game_imagelink" placeholder="Bild-Link" maxlength="255" value="<?php echo $game->getImagelink() ?>" />
                        </li>
                        <li>
                            <label for="game_reportlink">Bericht-Link</label>
                            <input type="text" name="game_reportlink" placeholder="Bericht-Link" maxlength="255" value="<?php echo $game->getReportlink() ?>" />
                        </li>
						<li>
                                                        <label for="game_goalshome">Tore Heim</label>
							<select id="game_goalshome" name="game_goalshome">
							<?php for ($i = 0; $i <= 15; $i++) { ?>
							<option value="<?php echo $i; ?>" <?php if ($game->getGoalshome() == $i) { echo "selected"; } else { echo ""; } ?>><?php echo $i; ?></option>
							<?php } ?>
                                                        </select>
						</li>
						<li>
                                                        <label for="game_goalsaway">Tore Gast</label>
                                                        <select id="game_goalsaway" name="game_goalsaway">
							<?php for ($i = 0; $i <= 15; $i++) { ?>
							<option value="<?php echo $i; ?>" <?php if ($game->getGoalsaway() == $i) { echo "selected"; } else { echo ""; } ?>><?php echo $i; ?></option>
							<?php } ?>
                                                        </select>
                                                </li>
						<li>
							<label for="game_team">Team</label>
							<select name="game_team">
							<?php foreach ($teams as $team) { ?>
							<option value="<?php echo $team->getId(); ?>" <?php if ($team->getId() == $game->getTeam()) { echo "selected"; } else { echo ""; } ?>><?php echo $team->getName(); ?></option>
							<?php } ?>
							</select>
						</li>
						<li>
							<label for="game_season">Saison</label>
							<select name="game_season">
							<?php foreach ($seasons as $season) { ?>
							<option value="<?php echo $season->getId(); ?>" <?php if ($season->getId() == $game->getSeason()) { echo "selected"; } else { echo ""; } ?>><?php echo $season->getName(); ?></option>
							<?php } ?>
							</select>
						</li>
						<li>
							<label for="game_venue">Ort</label>
							<select name="game_venue">
							<?php foreach ($gamevenues as $gamevenue) { ?>
							<option value="<?php echo $gamevenue->getId(); ?>" <?php if ($gamevenue->getId() == $game->getVenue()) { echo "selected"; } else { echo ""; } ?>><?php echo $gamevenue->getCity().": ".$gamevenue->getName(); ?></option>
							<?php } ?>
							</select>
						</li>
						<li id="torschuetzen">
							<label for="game_scorers[]">Torschützen</label>
							<?php foreach ($scorers as $scorer) { ?>
							<select name="game_scorers[]">
                                                                <option value="-1" <?php if ($scorer->getPlayer_id() == -1) { echo "selected"; } else { echo ""; } ?>>bitte Auswählen</option>
                                                                <?php foreach($players as $player) { ?>
                                                                <option value="<?php echo $player->getId(); ?>" <?php if ($player->getId() == $scorer->getPlayer_id()) { echo "selected"; } else { echo ""; } ?>><?php echo $player->getFirstname()." ".$player->getLastname(); ?></option>
								<?php } ?>
							</select>
							<?php } ?>
						</li>
                    </ul>
                    <div class="buttons">
                        <input type="submit" name="saveChanges" value="speichern" />
                        <input type="submit" formnovalidate name="cancel" value="abbrechen" />
                  </div>
                </form>
            </div>
        </div>
    
	<script type='text/javascript'>
		$( document ).ready(function() {
			$("#game_goalshome, #game_goalsaway, #game_type").change(function() {
                                $("#torschuetzen").remove();
			});
		});
	</script>
	
    </body>
</html>